#include "imMain.h"

// VTK
#include <vtkSmartPointer.h>
#include <vtkActor.h>

// File-Specific Includes
#include "imgui_vtk_demo.h" // Actor generator for this demo

imMain::imMain() {
    // Setup pipeline
    auto actor = SetupDemoPipeline();
    vtkViewer_.getRenderer()->SetBackground(0, 0, 0); // Black background
    vtkViewer_.addActor(actor);
}

void imMain::open() {

    //// 4. Show a simple VtkViewer Instance (Always Open)
    //ImGui::SetNextWindowSize(ImVec2(360, 240), ImGuiCond_FirstUseEver);
    //ImGui::Begin("Vtk Viewer 1", nullptr, VtkViewer::NoScrollFlags());
    //vtkViewer1.render(); // default render size = ImGui::GetContentRegionAvail()
    //ImGui::End();

    // 5. Show a more complex VtkViewer Instance (Closable, Widgets in Window)
    ImGui::SetNextWindowSize(ImVec2(720, 480), ImGuiCond_FirstUseEver);

    if (viewer_open_) {
        ImGui::Begin("Vtk Viewer 2", &viewer_open_, VtkViewer::NoScrollFlags());

        // Other widgets can be placed in the same window as the VTKViewer
        // However, since the VTKViewer is rendered to size ImGui::GetContentRegionAvail(),
        // it is best to put all widgets first (i.e., render the VTKViewer last).
        // If you want the VTKViewer to be at the top of a window, you can manually calculate
        // and define its size, accounting for the space taken up by other widgets

        auto renderer = vtkViewer_.getRenderer();
        if (ImGui::Button("VTK Background: Black")) {
            renderer->SetBackground(0, 0, 0);
        }
        ImGui::SameLine();
        if (ImGui::Button("VTK Background: Red")) {
            renderer->SetBackground(1, 0, 0);
        }
        ImGui::SameLine();
        if (ImGui::Button("VTK Background: Green")) {
            renderer->SetBackground(0, 1, 0);
        }
        ImGui::SameLine();
        if (ImGui::Button("VTK Background: Blue")) {
            renderer->SetBackground(0, 0, 1);
        }
        static float vtk2BkgAlpha = 0.2f;
        ImGui::SliderFloat("Background Alpha", &vtk2BkgAlpha, 0.0f, 1.0f);
        renderer->SetBackgroundAlpha(vtk2BkgAlpha);

        vtkViewer_.render();

        ImGui::End();
    }
}